﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command.ApproveCommand;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace B.S.DataBase.MyRead.API.Appicant.CommandHandler.ApproveCommandHandler
{
    /// <summary>
    /// 反填获取审批结果-命令执行     请假id 审批人id
    /// </summary>
    public class FanTianAPPlicantStatusCommandHandler : IRequestHandler<FanTianAPPlicantStatusCommand, APIResult<LeaveRecordModel>>
    {
        private readonly IBaseRepository<LeaveRecordModel> recorRepos;

        public FanTianAPPlicantStatusCommandHandler(IBaseRepository<LeaveRecordModel> recorRepos)
        {
            this.recorRepos = recorRepos;
        }

        /// <summary>
        /// 反填获取审批结果
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<LeaveRecordModel>> Handle(FanTianAPPlicantStatusCommand request, CancellationToken cancellationToken)
        {
            APIResult<LeaveRecordModel> result = new APIResult<LeaveRecordModel>();
            var list = await recorRepos.GetAll().Result.FirstOrDefaultAsync(x=>x.LeaveId == request.LeaveId && x.UserId == request.UserId);
            result.data = list;
            return await Task.FromResult(result);
        }
    }
}
